package app.util;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;

import app.Main;
import app.conn.WebDB;

public class Storage {

	private boolean sdSource;
	private File sdRoot;

	// Data files
	private File recFile;
	private File setFile;
	private File cnfFile;

	private int rec_delay;
	private LinkedList<Record> records;
	private TimeCnf[] wateringTimes;
	private TimeCnf[] ventilationTimes;

	public Storage() {
		records = new LinkedList<Record>();
	}

	public void setSource(boolean sdSource) {
		this.sdSource = sdSource;
	}

	public boolean isSdSource() {
		return this.sdSource;
	}

	public void setSdRoot(File sdRoot, boolean open) {
		this.sdRoot = sdRoot;
	}

	public boolean downloadData(WebDB conn, String token, int unitid) {
		return false;
	}

	public boolean uploadData(WebDB conn, String token, int unitid) {
		return false;
	}

	public boolean readData(File f) {
		return false;
	}

	public boolean saveData(File f) {
		return false;
	}

	public long getTimeMin() {
		return 0;
	}

	public long getTimeMax() {
		return 0;
	}

	public String[] getWateringTimes() {
		return null;	
	}

	public String[] getVentilationTimes() {
		return null;
	}


	/**
	 * Class for store time and delay config
	 * 
	 * @author Lukas Vavra
	 *
	 */
	public class TimeCnf {
		private long time;
		private int delay;

		public TimeCnf() {}

		public TimeCnf(long time, int delay) {
			this.setTime(time);
			this.setDelay(delay);
		}

		public long getTime() {
			return time;
		}

		public void setTime(long time) {
			this.time = time;
		}

		public int getDelay() {
			return delay;
		}

		public void setDelay(int delay) {
			this.delay = delay;
		}

		public String toString() {
			Date date = new Date(getTime());
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
			return sdf.format(date).concat(", ").concat(Integer.toString(delay)).concat("s");
		}

		public void parse(String timecnf) {

		}
	}

	/**
	 * Class for store one record
	 * 
	 * 
	 * @author Lukas Vavra
	 *
	 */
	public class Record {
		private long time;
		private char type;
		private int[] value;

		public Record() {}

		public Record(long time, char type, int[] value) {
			this.setTime(time);
			this.setType(type);
			this.setValue(value);
		}

		public long getTime() {
			return time;
		}

		public void setTime(long time) {
			this.time = time;
		}

		public char getType() {
			return type;
		}

		public void setType(char type) {
			this.type = type;
		}

		public int[] getValue() {
			return value;
		}

		public void setValue(int[] value) {
			this.value = value;
		}
	}

}
